/**
* Oxide
*
* Copyright (c) 2011 Dinosaur Kick Pty Ltd, All rights reserved.
*
* This source code is made available under the "Modified BSD" licensing arrangement.
* See license.txt for details.
*/
// ----------------------------------------------------------------------------
#include <boost/shared_ptr.hpp>
#include "oxide-common/ast/ast_fwd.hpp"
#include "message_list.hpp"
// ----------------------------------------------------------------------------
#ifndef O2_PARSE_RESULT_INC
#define O2_PARSE_RESULT_INC
namespace o2 {
namespace parse {
// ----------------------------------------------------------------------------

template <typename StringT>
class basic_result
{
	public:
		typedef StringT string_type;
		typedef basic_message_list<string_type> message_list_type;
		typedef o2::ast::basic_root<string_type> root_type;
		typedef boost::shared_ptr<root_type> root_ptr;
		
		basic_result(void)
			{ }
		
		basic_result(root_ptr root, const message_list_type& messages)
			: m_ast(root)
			, m_messages(messages)
			{ }

		explicit basic_result(const message_list_type& messages)
			: m_messages(messages)
			{ }

		bool success(void) const
			{ return m_messages.level() == ML_NONE; }

		operator bool (void) const
			{ return success(); }

		bool operator! (void) const
			{ return !success(); }

		root_ptr ast(void) const
			{ return m_ast; }

		const message_list_type& messages(void) const
			{ return m_messages; }

	private:
		root_ptr m_ast;
		message_list_type m_messages;
};

// ----------------------------------------------------------------------------

typedef basic_result<std::string> result;
typedef basic_result<std::wstring> wresult;

// ----------------------------------------------------------------------------
} // namespace parse
} // namespace o2
#endif // O2_PARSE_RESULT_INC
// ----------------------------------------------------------------------------
